package com.sicau.smarttraceplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicau.smarttraceplatform.entity.Good;
import com.sicau.smarttraceplatform.entity.param.good.GoodQueryParam;
import com.sicau.smarttraceplatform.entity.vo.PageDataVO;
import com.sicau.smarttraceplatform.mapper.GoodMapper;
import com.sicau.smarttraceplatform.service.GoodService;
import com.sicau.smarttraceplatform.utils.PageUtil;
import com.sicau.smarttraceplatform.utils.QueryWrapperUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 商品信息 服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2020-05-24
 */
@Service
public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements GoodService {

    @Resource
    private GoodMapper goodMapper;

    @Override
    public PageDataVO<Good> queryGoodByCondition(GoodQueryParam goodQueryParam) {
        Page page = new Page(goodQueryParam.getCurrentPage(),goodQueryParam.getPageSize());
        QueryWrapper<Good> queryWrapper = QueryWrapperUtil.getQueryWrapper(Good.class, GoodQueryParam.class, goodQueryParam);
        queryWrapper.orderByDesc("id");
        return PageUtil.convert(goodMapper.selectPage(page, queryWrapper));
    }
}
